'use strict';
module.exports = {
	/**
	 * 公众号推送入口
	 * @url client/mp/pub/index 前端调用的url参数地址
	 * data 请求参数
	 */
	main: async (event) => {
		let {
			data = {}, userInfo, util, originalParam
		} = event;
		let {
			customUtil,
			config,
			pubFun,
			vk,
			db,
			_
		} = util;
		let {
			uid
		} = data;
		let res = {
			code: 0,
			msg: "",
		};
		// 业务逻辑开始-----------------------------------------------------------
		// 所有的逻辑都在这里写
		// 比如上边写到的

		const result = await uniCloud.httpclient.request(
			'https://api.weixin.qq.com/cgi-bin/message/template/send?access_token=' + data.accessToken, {
				method: 'POST',
				dataType: 'json',
				data: JSON.stringify({
					touser: data.openId,
					template_id: data.template_id,
					data: data.data
				}),
			});
		if (result.data.code === 200) {
			res.msg = '模板消息发送成功'
			res.code = 200
		} else {
			res.code = result.data.errcode
			res.msg = '模板消息发送失败'
		}
		// 业务逻辑结束-----------------------------------------------------------

		res.data = result.data
		return res;
	}
}